package com.cy;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.sound.sampled.LineUnavailableException;
import java.lang.invoke.LambdaConversionException;


@SpringBootApplication
public class ScaProviderApplication {
    //org.slf4j.Logger (Log4J,Logback都是基于此规范实现的日志库)
    //org.slf4j.LoggerFactory
    //getLogger(哪个类中输出的日志)
    private static final Logger log = LoggerFactory.getLogger(ScaProviderApplication.class);

    public static void main(String[] args) {
        SpringApplication.run(ScaProviderApplication.class, args);
    }

    @RefreshScope//当配置中心的内容发生变化,重新发布时,用于刷新类中的配置信息
    @RestController
    public class ProviderController{

        @Value("${page.pagesize:3}")
        private Integer pageSize;

        @Value("${server.port}")
        private String server;

        /**
         * 读取配置中心的日志级别
         */
        @Value("${logging.level.com.cy:info}")//":"为默认值
        private String logLevel;

        @Value("${server.tomcat.threads.max:200}")
        private Integer maxThread;

        @GetMapping(value = "/provider/echo/{msg}")
        public String doEcho(@PathVariable String msg) {//Echo为回显
            if (msg==null || msg.length()<3)
                throw new IllegalArgumentException("参数不合法");
            return server + "say:Hello Nacos Discovery" + msg;
        }
        @GetMapping("/provider/doGetLogLevel")
        public String doGetLogLevel(){
            //日志优先级 trace<debug<info<warn<error
//            log.trace("==log.trace==");//跟踪
//            log.debug("==log.debug==");//调试
//            log.info("==log.info==");//常规信息
//            log.warn("==log.warn==");//警告
//            log.error("==log.error==");//错误信息
            return "log level is " + logLevel;
        }
        @GetMapping("/provider/doGetMaxThread")
        public String doGetMaxThread(){
            return "server.threads.max is  "+maxThread;
        }
        @GetMapping("/provider/pageSize")
        public String doGetPageSize(){
            return "page size is "+pageSize;
        }
    }
}
